<template>
  <div class="safeCheckConfirm">
    <secondTopPanel>
      <div slot='title'>结果确认</div>
    </secondTopPanel>
    <div class="clear">
      <evanForm ref="form" class="evan-form" :label-style="{width:'220upx',paddingRight:'20upx'}" :model='form' :rules='rules'>
        <evanFormItem label='' label-position='top'>
          <uni-data-checkbox v-model="form.needProgrammeParse" :multiple="true" :localdata="range" @change="isSceneChange"></uni-data-checkbox>
        </evanFormItem>
        <evanFormItem label='' label-position='top'>
          <uni-data-checkbox v-model="form.needReuniteParse" :multiple="true" :localdata="range2" @change="isSceneChange2"></uni-data-checkbox>
        </evanFormItem>
        <evanFormItem label='备注' prop="remark">
          <textarea class="form-input textarea" v-model="form.remark" placeholder="请输入备注"></textarea>
        </evanFormItem>
      </evanForm>
    </div>
    <!-- <button v-if="form.needAgree==='1'" style="width:90%" type="primary" @click="feedSubmitForm">结果确认</button> -->
    <br>
  </div>
</template>

<script>
import evanForm from '@/components/evan-form/evan-form.vue'
import evanFormItem from '@/components/evan-form-item/evan-form-item.vue'
import { userPointsList, pointsRanking } from "@/api/integral.js";
import {
  safeInspectResList,
  safeInspectCompanyOne,
  safeInspectCompanyFeedback,
} from "@/api/safeCheck";
import secondTopPanel from '@/pages/component/top-panel/secondTopPanel.vue'

export default {
  name: 'safeCheckConfirm',
  components: { secondTopPanel, evanForm, evanFormItem, },
  data () {
    return {
      range: [{ "value": 1, "text": "是否需要整改方案" }],
      range2: [{ "value": 1, "text": "是否需要复核" }],
      resCompanyId: null,
      form: {},
      rules: {}
    }
  },
  onLoad: function (option) {
    this.resCompanyId = option.id
    this.safetyCheckOne(option.id)
  },

  onShow () {
    this.safetyCheckOne(this.resCompanyId)
  },
  methods: {
    // 选择是否现场整改
    isSceneChange (e) {
      console.log(e)
      this.form.needProgramme = e.detail.data[0]?.value || '0'
    },
    // 选择是否现场整改
    isSceneChange2 (e) {
      this.form.needReunite = e.detail.data[0]?.value || '0'
    },
    // 重置表单
    reset () {
      this.form = {
        companyId: null,
        companyName: null,
        inspectTime: null,
        leader: null,
        member: null,
        name: null,
        safeCompany: null,
        safeCompanyParse: null,
        safeCompanyIds: null,
        safeCompanyIdsParse: null,
        status: null,
        safeCompanyName: null,
        findTime: null,
        needAgree: null,
        needProgramme: null,
        needReunite: null,
        needProgrammeParse: [],
        needReuniteParse: [],
        remark: null,
      }
    },
    // 安全检查单条
    safetyCheckOne (id) {
      this.reset()
      safeInspectCompanyOne({ id: id }).then(response => {
        if (response.code === 200) {
          for (const d in this.form) {
            this.form[d] = response.data[d]
          }
          this.form.id = id
          this.form['safeCompanyParse'] = response.data.safeCompany?.split(',') || []
          this.form['safeCompanyIdsParse'] = response.data.safeCompanyIds?.split(',') || []
          this.form['needProgrammeParse'] = [Number(response.data.needProgramme)] || []
          this.form['needReuniteParse'] = [Number(response.data.needReunite)] || []
          console.log(this.form)
        }
      })
    },
    // 结果确认 按钮
    feedSubmitForm () {
      const id = this.form.id
      uni.showLoading({
        title: '确认中'
      });
      safeInspectCompanyFeedback({
        id: id,
        needProgramme: this.form.needProgramme,
        needReunite: this.form.needReunite,
        remark: this.form.remark
      }).then((response) => {
        uni.hideLoading();
        uni.showLoading({
          title: '确认成功',
          icon: 'none',
        });
        setTimeout(() => {
          uni.navigateBack({
            delta: 1
          })
        }, 1000);
      })
    },
  },
}
</script>

<style scoped lang="scss">
.form-input {
  font-size: 28upx;
  text-align: left;
  width: 100%;
  box-sizing: border-box;
  height: 60upx;
  &.textarea {
    height: 200upx;
    padding: 24rpx 0;
    text-align: left;
  }
}
.safeCheckConfirm {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}
.clear {
  flex: 1;
  padding-top: 100upx;
}
.globalTitle {
}
</style>
